<?php
/**
 * Created by PhpStorm.
 * User: jochen
 * Date: 2017/1/9
 * Time: 上午10:14
 */

require_once 'ModelTestCase.php';
use EWeiLink\JuPai\Contact;
use EWeiLink\JuPai\Customer;
use EWeiLink\JuPai\Planner;
use EWeiLink\JuPai\User;
use EWeiLink\JuPai\Services\PlannerRepo;

class PlannerTest extends ModelTestCase
{
    /**
     * 测试理财师资源列表
     */
    public function testPlannerList(){
        $planner = new PlannerRepo();
        $res = $planner->list();
        dd(json_encode($res, 128+256));
    }
    public function testCreateOne()
    {
        $planner = Planner::create();
        $this->assertNotEmpty($planner->id);
        $planner->delete();
    }

    public function testFindByUser()
    {
        // 测试准备数据
        $user = User::firstOrCreate(['name' => 'tester']);
        $this->preDestroy($user);
        $this->assertNotNull($user);
        $planner = Planner::create([
            'user_id' => $user->id,
            'name' => $user->name
        ]);
        $this->assertEquals($planner->user_id, $user->id);
        $this->preDestroy($planner);
        $this->assertNotNull($planner);

        // 测试逻辑
        $tp = Planner::findByUser($user)->first();
        $this->assertNotNull($tp, 'User must exists');
        $this->assertEquals($planner->id, $tp->id);
    }

    public function testContact()
    {
        $contact = Contact::firstOrCreate([
            'clientUin' => 123123,
            'plannerId' => 1,
            'customerId' => 11,
            'ewlink_id' => Customer::first()->id,
        ]);
        $this->assertNotNull($contact);
        $this->assertEquals(123123, $contact->clientUin);
        $this->assertNotNull($contact->wechat);
        dumps($contact->wechat);
    }
}
